package com.ruoyi.common.gscUtil.StudyUtil.SocketUtil;

import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) {
        String serverAddress = "localhost"; // 服务器地址
        int port = 12345; // 服务器端口号

        try (Socket socket = new Socket(serverAddress, port)) {
            System.out.println("已连接到服务器");

            // 获取输入输出流
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            // 发送请求
            out.println("Hello, Server!");

            // 接收响应
            String serverResponse = in.readLine();
            System.out.println("收到服务器响应: " + serverResponse);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}